package com.ziyun.erp.web.modules.order.controller;

import com.ziyun.erp.common.e.order.*;
import com.ziyun.erp.common.utils.JsonUtils;
import com.ziyun.erp.common.utils.UserUtils;
import com.ziyun.erp.modules.logistics.dto.ErpLogisticsDto;
import com.ziyun.erp.modules.order.dto.PaperItemAuditDto;
import com.ziyun.erp.modules.order.service.OrderInfoService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.modules.sys.entity.SysUserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 订单基础信息表
 *
 * @author guizhao
 * @date 2018-08-03 10:40:47
 */
@RestController
@RequestMapping("order/paperOrder")
public class paperOrderInfoController {

    @Autowired
    private OrderInfoService orderInfoService;

    /**
     * 列表
     */
    @RequestMapping("/paperOrderList")
    public R paperOrderList(@RequestParam Map<String, Object> params){
        PageUtils page = orderInfoService.queryPagePaperOrderList(params);

        // 存放枚举类到userdata
        Map<String, List> mapEnum = new HashMap<>();
        mapEnum.put("orderInfoStatusEnum", JsonUtils.enumToList(OrderInfoStatusEnum.class));
        mapEnum.put("payTypeEnum", JsonUtils.enumToList(PayTypeEnum.class));

        R r = R.ok();
        r.put("page", page);
        r.put("userData", mapEnum);
        return r;
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{orderId}")
    public R info(@PathVariable("orderId") Long orderId){
        return orderInfoService.paperOrderInfo(orderId);
    }

    /**
     * 大纸审核
     * @param params  orderInfo：订单信息  orderItem：商品集合  remark: 客服备注
     * @return
     */
    @PostMapping("/paperAudit")
    public R paperAudit(@RequestBody Map<String,Object> params){
        SysUserEntity curentUser = UserUtils.getCurentUser();
        Long userId = curentUser.getUserId();
        String username = curentUser.getUsername();
        return orderInfoService.paperAudit(params, userId, username);
    }

    /**
     * 大纸订单审核
     */
    @PostMapping("/paperOrderAudit")
    public R paperOrderAudit(@RequestBody PaperItemAuditDto paperItemAuditDto){
        SysUserEntity curentUser = UserUtils.getCurentUser();
        Long userId = curentUser.getUserId();
        String username = curentUser.getUsername();
        return orderInfoService.paperOrderAudit(paperItemAuditDto, userId, username);
    }

    /**
     * 获取发货信息
     */
    @RequestMapping("/sendLogisticsInfo")
    public R sendLogisticsInfo(@RequestParam("orderId") String orderId){
        return orderInfoService.sendLogisticsInfo(orderId);
    }

    /**
     * 添加物流
     * @param erpLogisticsDto
     * @return
     */
    @RequestMapping("/saveOrderLogisticsInfo")
    public R saveOrderLogisticsInfo(@RequestBody ErpLogisticsDto erpLogisticsDto){
        String username = UserUtils.getCurentUser().getUsername();
        return orderInfoService.saveOrderLogisticsInfo(erpLogisticsDto, username);
    }

}
